import { computed, reactive, ref } from "vue";

export default function InitHook(state: any) {
  const { passData } = state;
  const formState = reactive<ApprovalCenter.ApproveSubmit>({
    finCloseCase: 0,
    approvalList: [],
    remark: "",
    file: [],
    isCloseCase: 0,
    companyProportion: 0,
    bizProportion: 0
  });
  const loading = ref<boolean>(false);
  const formDataRef = ref<any>(null);
  //判断是否财务部
  const isFinance = computed(() => {
    const arr = ["财", "务", "部"];
    return arr.every((t: string) => passData.value.progress.includes(t));
  });

  const getState = new Map([
    [0, "待审批"],
    [1, "审批驳回"],
    [2, "审批通过"],
    [3, "待确认"],
    [4, "已确认"],
    [10, "未知"]
  ]);

  const getColor = (e: number): string => {
    const colorMap: { [key: number]: string } = {
      1: "red",
      2: "green",
      4: "green",
      3: "blue",
      0: "blue"
    };

    return colorMap[e] ?? "blue";
  };
  const isConfirmationHandle = (e: number): number => {
    const mapping: { [key: number]: number } = {
      0: 3,
      1: 4,
      2: 1
    };

    return mapping[e] ?? 10;
  };
  return { formState, loading, formDataRef, isFinance, getColor, isConfirmationHandle, getState };
}
